﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using PenguinPublishNS.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Schema;
using Newtonsoft.Json.Linq;
using System.IO;


namespace PenguinPublishNS
{
    class jsonUtils
    {
        // utilities here to verify the json file and perhaps validate other aspects of entries

        public static bool jsonSchemaCheck()
        {
            // parse schema from HostServer class, then parse file for schema validation

            var jsonSchemaGenerator = new JsonSchemaGenerator();
            var myType = typeof(HostServer);
            var schema = jsonSchemaGenerator.Generate(myType);
            // schema.Title = myType.Name; // this doesn't seem to get done within the generator

            var streamR = new StreamReader(PenguinPublish.dataPath + @"\dataHostSetting.json");
            String readSettings = streamR.ReadToEnd();
            streamR.Close();
            JObject hostSettingJson = JObject.Parse("{\"root\": " + readSettings + "}");
            

            bool validJSON = hostSettingJson.IsValid(schema);

            return validJSON;
        }

    }
}
